<?php $this->load->view('provider/template/_begin') ?>
<div class="form1">
  <table class="table2">
    <tr>
      <td>
        <div class="search">
          <span id="ctl00_Label1" class="text_input">Search</span>
          <form action="<?php echo site_url('provider/promotion/check') ?>" method="post">
            <input type="text" placeholder="Enter dowload code" value="<?php echo isset($download_code) ? $download_code : '' ?>" 
                   id="fulltextSearchText" class="input_search" name="download_code"/>
            <input type="submit" value="" id="ctl00_Button1" class="button_search" 
                   style="background-color: Transparent; border-style: None;"/>
          </form>
        </div>
      </td>      
    </tr>
  </table>
  <div class="clearer"></div>
  <?php if (!empty($promotion)) { ?>
  <fieldset>
      <legend style="font-weight: bold;padding:5px">Promotion detail</legend> 
      <table class="table1">
        <tr>
          <td>End user</td>
          <td><?php echo $this->end_user_model->to_string($download['end_user_id']) ?></td>
        </tr>
        <tr>
          <td>Code</td>
          <td><?php echo $download['code'] ?></td>
        </tr>
        <tr>
          <td>Downloaded at</td>
          <td><?php echo empty($promotion["date_create"]) ? '' : date($this->setting_model->item('date_format'), $promotion["date_create"]) ?></td>
        </tr>
        <tr>
          <td>Status</td>
          <td>
            <?php $PROMOTION_DOWNLOAD_STATUS = array(PROMOTION_DOWNLOAD_NEW => 'NEW', PROMOTION_DOWNLOAD_GOT => 'GOT', 
                PROMOTION_DOWNLOAD_CANCEL => 'CANCEL', PROMOTION_DOWNLOAD_REJECT => 'REJECT');
            echo isset($PROMOTION_DOWNLOAD_STATUS[$download['status']]) ? $PROMOTION_DOWNLOAD_STATUS[$download['status']] : $PROMOTION_DOWNLOAD_STATUS[PROMOTION_DOWNLOAD_NEW];
            ?>
          </td>
        </tr>
        <?php if($download['status'] == PROMOTION_DOWNLOAD_NEW) { ?>
        <tr>
          <td colspan="2">
            <button onclick="jQuery('form').attr('action','<?php echo site_url('provider/promotion/get_promotion') ?>');jQuery('form').submit()">GET</button>
          </td>
        </tr>
        <?php } ?>
      </table>
  </fieldset>
  <?php }
  if (!empty($promotion)) { ?>
    <fieldset>
      <legend style="font-weight: bold;padding:5px">Promotion detail</legend>  
      <table class="table1">
        <tr>
          <td class="text4">Title:</td>
          <td>
            <label><?php echo empty($promotion["title"]) ? "" : $promotion["title"] ?></label>
          </td>
          <td class="text4">Code:</td>
          <td><label><?php echo empty($promotion["code"]) ? "" : $promotion["code"] ?></label></td>
        </tr>
        <tr>
          <td class="text4">Categories:</td>
          <td>
            <label>
              <?php
              foreach ($promotion["category"] as $category) {
                echo $this->category_model->to_string($category) . ', ';
              }
              ?>
            </label>
          </td> 
          <td class="text4">Related promotion:</td>
          <td>
            <label>
              <?php foreach ($promotion["promotion2_id"] as $relate) { ?>
                <a href="<?php echo site_url('provider/promotion/show/' . $relate) ?>" style="padding-right: 10px">
                  <?php echo $this->promotion_model->to_string($relate) ?>
                </a>
              <?php } ?>
            </label>
          </td>
        </tr>
        <tr>
          <td class="text4">Description:</td>
          <td colspan="3">
            <label><?php echo empty($promotion["description"]) ? "" : $promotion["description"] ?></label>
          </td>
        </tr>    
        <tr>
          <td class="text4">Start date:</td>
          <td><label><?php echo empty($promotion["start_date"]) ? '' : date($this->setting_model->item('date_format'), $promotion["start_date"]) ?></label></td>
          <td class="text4">Total promotion:</td>
          <td>
            <label><?php echo empty($promotion["max_download"]) ? "" : $promotion["max_download"] ?></label>
          </td>
        </tr>
        <tr>
          <td class="text4">Expire date:</td>
          <td><label><?php echo empty($promotion["end_date"]) ? '' : date($this->setting_model->item('date_format'), $promotion["end_date"]) ?></label></td>        
          <td class="text4">Limit per person:</td>
          <td><label><?php echo empty($promotion["max_per_person"]) ? "" : $promotion["max_per_person"] ?></label></td>
        </tr>
        <tr>
          <td class="text4">Country:</td>
          <td><label><?php echo $this->country_model->to_string($promotion['country_id']) ?></label>
          </td>
          <td class="text4">Support channel:</td>
          <td>
            <?php
            $support_channel = array(
                PROMOTION_CHANNEL_ALL => $this->lang->line('label.promotion.support_channel.all'),
                PROMOTION_CHANNEL_EMAIL => $this->lang->line('label.promotion.support_channel.email'),
                PROMOTION_CHANNEL_SMS => $this->lang->line('label.promotion.support_channel.sms'));
            ?>
            <label><?php echo isset($support_channel[$promotion['support_channel']]) ? $support_channel[$promotion['support_channel']] : '' ?></label>
          </td>        
        </tr>
        <tr>
          <td class="text4">State:</td>
          <td><label><?php echo $this->state_model->to_string($promotion['state_id']) ?></label>
          </td>
          <td class="text4">Support encode:</td>
          <td>
            <?php
            $support_encode = array(
                PROMOTION_ENCODE_ALL => $this->lang->line('label.promotion.support_encode.all'),
                PROMOTION_ENCODE_BARCODE => $this->lang->line('label.promotion.support_encode.barcode'),
                PROMOTION_ENCODE_TEXT => $this->lang->line('label.promotion.support_encode.text'));
            ?>
            <label><?php echo isset($support_encode[$promotion['support_encode']]) ? $support_encode[$promotion['support_encode']] : '' ?></label>
          </td>        
        </tr>
        <tr>
          <td class="text4">City:</td>
          <td>
            <label><?php echo $this->city_model->to_string($promotion['city_id']) ?></label>
          </td>
        </tr>
        <tr>
          <td class="text4">Image(s):</td>
          <td colspan="3">
            <div style="float: left;width: 100%;padding-bottom: 5px;">
              <?php foreach ($promotion['images'] as $image) { ?>
                <img width="100px" style="padding: 5px"
                     src="<?php echo site_url('admin/' . 'promotion_media/preview/' . $image['id']) ?>" alt=""/>
                   <?php } ?>
            </div>
          </td>
        </tr>      
      </table>
    </fieldset>
  <?php } ?>
  <div class="clearer"></div>
</div>
<?php $this->load->view('provider/template/_end') ?>
